home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / var / lib / python-support / python2.6 / dbus / service.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  25.1 KB  |  724 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __all__ = ('BusName', 'Object', 'method', 'signal')
  5. __docformat__ = 'restructuredtext'
  6. import sys
  7. import logging
  8. import operator
  9. import traceback
  10.  
  11. try:
  12.     import thread
  13. except ImportError:
  14.     import dummy_thread as thread
  15.  
  16. import _dbus_bindings
  17. from dbus import SessionBus, Signature, Struct, validate_bus_name, validate_object_path, INTROSPECTABLE_IFACE, ObjectPath
  18. from dbus.decorators import method, signal
  19. from dbus.exceptions import DBusException, NameExistsException, UnknownMethodException
  20. from dbus.lowlevel import ErrorMessage, MethodReturnMessage, MethodCallMessage
  21. from dbus.proxies import LOCAL_PATH
  22. _logger = logging.getLogger('dbus.service')
  23.  
  24. class _VariantSignature(object):
  25.     """A fake method signature which, when iterated, yields an endless stream
  26.     of 'v' characters representing variants (handy with zip()).
  27.  
  28.     It has no string representation.
  29.     """
  30.     
  31.     def __iter__(self):
  32.         '''Return self.'''
  33.         return self
  34.  
  35.     
  36.     def next(self):
  37.         """Return 'v' whenever called."""
  38.         return 'v'
  39.  
  40.  
  41.  
  42. class BusName(object):
  43.     '''A base class for exporting your own Named Services across the Bus.
  44.  
  45.     When instantiated, objects of this class attempt to claim the given
  46.     well-known name on the given bus for the current process. The name is
  47.     released when the BusName object becomes unreferenced.
  48.  
  49.     If a well-known name is requested multiple times, multiple references
  50.     to the same BusName object will be returned.
  51.  
  52.     Caveats
  53.     -------
  54.     - Assumes that named services are only ever requested using this class -
  55.       if you request names from the bus directly, confusion may occur.
  56.     - Does not handle queueing.
  57.     '''
  58.     
  59.     def __new__(cls, name, bus = None, allow_replacement = False, replace_existing = False, do_not_queue = False):
  60.         '''Constructor, which may either return an existing cached object
  61.         or a new object.
  62.  
  63.         :Parameters:
  64.             `name` : str
  65.                 The well-known name to be advertised
  66.             `bus` : dbus.Bus
  67.                 A Bus on which this service will be advertised.
  68.  
  69.                 Omitting this parameter or setting it to None has been
  70.                 deprecated since version 0.82.1. For backwards compatibility,
  71.                 if this is done, the global shared connection to the session
  72.                 bus will be used.
  73.  
  74.             `allow_replacement` : bool
  75.                 If True, other processes trying to claim the same well-known
  76.                 name will take precedence over this one.
  77.             `replace_existing` : bool
  78.                 If True, this process can take over the well-known name
  79.                 from other processes already holding it.
  80.             `do_not_queue` : bool
  81.                 If True, this service will not be placed in the queue of
  82.                 services waiting for the requested name if another service
  83.                 already holds it.
  84.         '''
  85.         validate_bus_name(name, allow_well_known = True, allow_unique = False)
  86.         if bus is None:
  87.             import warnings
  88.             warnings.warn('Omitting the "bus" parameter to dbus.service.BusName.__init__ is deprecated', DeprecationWarning, stacklevel = 2)
  89.             bus = SessionBus()
  90.         
  91.         if name in bus._bus_names:
  92.             return bus._bus_names[name]
  93.         if not allow_replacement or _dbus_bindings.NAME_FLAG_ALLOW_REPLACEMENT:
  94.             pass
  95.         if not replace_existing or _dbus_bindings.NAME_FLAG_REPLACE_EXISTING:
  96.             pass
  97.         if not do_not_queue or _dbus_bindings.NAME_FLAG_DO_NOT_QUEUE:
  98.             pass
  99.         name_flags = 0 | 0 | 0
  100.         retval = bus.request_name(name, name_flags)
  101.         if retval == _dbus_bindings.REQUEST_NAME_REPLY_PRIMARY_OWNER:
  102.             pass
  103.         elif retval == _dbus_bindings.REQUEST_NAME_REPLY_IN_QUEUE:
  104.             pass
  105.         elif retval == _dbus_bindings.REQUEST_NAME_REPLY_EXISTS:
  106.             raise NameExistsException(name)
  107.         elif retval == _dbus_bindings.REQUEST_NAME_REPLY_ALREADY_OWNER:
  108.             pass
  109.         else:
  110.             raise RuntimeError('requesting bus name %s returned unexpected value %s' % (name, retval))
  111.         bus_name = (name in bus._bus_names).__new__(cls)
  112.         bus_name._bus = bus
  113.         bus_name._name = name
  114.         bus._bus_names[name] = bus_name
  115.         return bus_name
  116.  
  117.     
  118.     def __init__(self, *args, **keywords):
  119.         pass
  120.  
  121.     
  122.     def __del__(self):
  123.         self._bus.release_name(self._name)
  124.  
  125.     
  126.     def get_bus(self):
  127.         '''Get the Bus this Service is on'''
  128.         return self._bus
  129.  
  130.     
  131.     def get_name(self):
  132.         '''Get the name of this service'''
  133.         return self._name
  134.  
  135.     
  136.     def __repr__(self):
  137.         return '<dbus.service.BusName %s on %r at %#x>' % (self._name, self._bus, id(self))
  138.  
  139.     __str__ = __repr__
  140.  
  141.  
  142. def _method_lookup(self, method_name, dbus_interface):
  143.     '''Walks the Python MRO of the given class to find the method to invoke.
  144.  
  145.     Returns two methods, the one to call, and the one it inherits from which
  146.     defines its D-Bus interface name, signature, and attributes.
  147.     '''
  148.     parent_method = None
  149.     candidate_class = None
  150.     successful = False
  151.     if dbus_interface:
  152.         for cls in self.__class__.__mro__:
  153.             if not candidate_class and method_name in cls.__dict__:
  154.                 if '_dbus_is_method' in cls.__dict__[method_name].__dict__ and '_dbus_interface' in cls.__dict__[method_name].__dict__:
  155.                     if cls.__dict__[method_name]._dbus_interface == dbus_interface:
  156.                         candidate_class = cls
  157.                         parent_method = cls.__dict__[method_name]
  158.                         successful = True
  159.                         break
  160.                     
  161.                 else:
  162.                     candidate_class = cls
  163.             
  164.             if candidate_class and method_name in cls.__dict__ and '_dbus_is_method' in cls.__dict__[method_name].__dict__ and '_dbus_interface' in cls.__dict__[method_name].__dict__ and cls.__dict__[method_name]._dbus_interface == dbus_interface:
  165.                 parent_method = cls.__dict__[method_name]
  166.                 successful = True
  167.                 break
  168.                 continue
  169.         
  170.     else:
  171.         for cls in self.__class__.__mro__:
  172.             if not candidate_class and method_name in cls.__dict__:
  173.                 candidate_class = cls
  174.             
  175.             if candidate_class and method_name in cls.__dict__ and '_dbus_is_method' in cls.__dict__[method_name].__dict__:
  176.                 parent_method = cls.__dict__[method_name]
  177.                 successful = True
  178.                 break
  179.                 continue
  180.         
  181.     if successful:
  182.         return (candidate_class.__dict__[method_name], parent_method)
  183.     if dbus_interface:
  184.         raise UnknownMethodException('%s is not a valid method of interface %s' % (method_name, dbus_interface))
  185.     dbus_interface
  186.     raise UnknownMethodException('%s is not a valid method' % method_name)
  187.  
  188.  
  189. def _method_reply_return(connection, message, method_name, signature, *retval):
  190.     reply = MethodReturnMessage(message)
  191.     
  192.     try:
  193.         reply.append(signature = signature, *retval)
  194.     except Exception:
  195.         e = None
  196.         logging.basicConfig()
  197.         if signature is None:
  198.             
  199.             try:
  200.                 signature = reply.guess_signature(retval) + ' (guessed)'
  201.             except Exception:
  202.                 e = None
  203.                 _logger.error('Unable to guess signature for arguments %r: %s: %s', retval, e.__class__, e)
  204.                 raise 
  205.             except:
  206.                 None<EXCEPTION MATCH>Exception
  207.             
  208.  
  209.         None<EXCEPTION MATCH>Exception
  210.         _logger.error('Unable to append %r to message with signature %s: %s: %s', retval, signature, e.__class__, e)
  211.         raise 
  212.  
  213.     connection.send_message(reply)
  214.  
  215.  
  216. def _method_reply_error(connection, message, exception):
  217.     name = getattr(exception, '_dbus_error_name', None)
  218.     if name is not None:
  219.         pass
  220.     elif getattr(exception, '__module__', '') in ('', '__main__'):
  221.         name = 'org.freedesktop.DBus.Python.%s' % exception.__class__.__name__
  222.     else:
  223.         name = 'org.freedesktop.DBus.Python.%s.%s' % (exception.__module__, exception.__class__.__name__)
  224.     (et, ev, etb) = sys.exc_info()
  225.     if isinstance(exception, DBusException) and not (exception.include_traceback):
  226.         contents = exception.get_dbus_message()
  227.     elif ev is exception:
  228.         contents = ''.join(traceback.format_exception(et, ev, etb))
  229.     else:
  230.         contents = ''.join(traceback.format_exception_only(exception.__class__, exception))
  231.     reply = ErrorMessage(message, name, contents)
  232.     connection.send_message(reply)
  233.  
  234.  
  235. class InterfaceType(type):
  236.     
  237.     def __init__(cls, name, bases, dct):
  238.         class_table = getattr(cls, '_dbus_class_table', { })
  239.         cls._dbus_class_table = class_table
  240.         interface_table = class_table[cls.__module__ + '.' + name] = { }
  241.         for b in bases:
  242.             base_name = b.__module__ + '.' + b.__name__
  243.             if getattr(b, '_dbus_class_table', False):
  244.                 for interface, method_table in class_table[base_name].iteritems():
  245.                     our_method_table = interface_table.setdefault(interface, { })
  246.                     our_method_table.update(method_table)
  247.                 
  248.         
  249.         for func in dct.values():
  250.             if getattr(func, '_dbus_interface', False):
  251.                 method_table = interface_table.setdefault(func._dbus_interface, { })
  252.                 method_table[func.__name__] = func
  253.                 continue
  254.         
  255.         super(InterfaceType, cls).__init__(name, bases, dct)
  256.  
  257.     
  258.     def _reflect_on_method(cls, func):
  259.         args = func._dbus_args
  260.         if func._dbus_in_signature:
  261.             in_sig = tuple(Signature(func._dbus_in_signature))
  262.         else:
  263.             in_sig = _VariantSignature()
  264.         if func._dbus_out_signature:
  265.             out_sig = Signature(func._dbus_out_signature)
  266.         else:
  267.             out_sig = []
  268.         reflection_data = '    <method name="%s">\n' % func.__name__
  269.         for pair in zip(in_sig, args):
  270.             reflection_data += '      <arg direction="in"  type="%s" name="%s" />\n' % pair
  271.         
  272.         for type in out_sig:
  273.             reflection_data += '      <arg direction="out" type="%s" />\n' % type
  274.         
  275.         reflection_data += '    </method>\n'
  276.         return reflection_data
  277.  
  278.     
  279.     def _reflect_on_signal(cls, func):
  280.         args = func._dbus_args
  281.         if func._dbus_signature:
  282.             sig = tuple(Signature(func._dbus_signature))
  283.         else:
  284.             sig = _VariantSignature()
  285.         reflection_data = '    <signal name="%s">\n' % func.__name__
  286.         for pair in zip(sig, args):
  287.             reflection_data = reflection_data + '      <arg type="%s" name="%s" />\n' % pair
  288.         
  289.         reflection_data = reflection_data + '    </signal>\n'
  290.         return reflection_data
  291.  
  292.  
  293.  
  294. class Interface(object):
  295.     __metaclass__ = InterfaceType
  296.  
  297. _MANY = object()
  298.  
  299. class Object(Interface):
  300.     '''A base class for exporting your own Objects across the Bus.
  301.  
  302.     Just inherit from Object and mark exported methods with the
  303.     @\\ `dbus.service.method` or @\\ `dbus.service.signal` decorator.
  304.  
  305.     Example::
  306.  
  307.         class Example(dbus.service.object):
  308.             def __init__(self, object_path):
  309.                 dbus.service.Object.__init__(self, dbus.SessionBus(), path)
  310.                 self._last_input = None
  311.  
  312.             @dbus.service.method(interface=\'com.example.Sample\',
  313.                                  in_signature=\'v\', out_signature=\'s\')
  314.             def StringifyVariant(self, var):
  315.                 self.LastInputChanged(var)      # emits the signal
  316.                 return str(var)
  317.  
  318.             @dbus.service.signal(interface=\'com.example.Sample\',
  319.                                  signature=\'v\')
  320.             def LastInputChanged(self, var):
  321.                 # run just before the signal is actually emitted
  322.                 # just put "pass" if nothing should happen
  323.                 self._last_input = var
  324.  
  325.             @dbus.service.method(interface=\'com.example.Sample\',
  326.                                  in_signature=\'\', out_signature=\'v\')
  327.             def GetLastInput(self):
  328.                 return self._last_input
  329.     '''
  330.     SUPPORTS_MULTIPLE_OBJECT_PATHS = False
  331.     SUPPORTS_MULTIPLE_CONNECTIONS = False
  332.     
  333.     def __init__(self, conn = None, object_path = None, bus_name = None):
  334.         """Constructor. Either conn or bus_name is required; object_path
  335.         is also required.
  336.  
  337.         :Parameters:
  338.             `conn` : dbus.connection.Connection or None
  339.                 The connection on which to export this object.
  340.  
  341.                 If None, use the Bus associated with the given ``bus_name``.
  342.                 If there is no ``bus_name`` either, the object is not
  343.                 initially available on any Connection.
  344.  
  345.                 For backwards compatibility, if an instance of
  346.                 dbus.service.BusName is passed as the first parameter,
  347.                 this is equivalent to passing its associated Bus as
  348.                 ``conn``, and passing the BusName itself as ``bus_name``.
  349.  
  350.             `object_path` : str or None
  351.                 A D-Bus object path at which to make this Object available
  352.                 immediately. If this is not None, a `conn` or `bus_name` must
  353.                 also be provided.
  354.  
  355.             `bus_name` : dbus.service.BusName or None
  356.                 Represents a well-known name claimed by this process. A
  357.                 reference to the BusName object will be held by this
  358.                 Object, preventing the name from being released during this
  359.                 Object's lifetime (unless it's released manually).
  360.         """
  361.         if object_path is not None:
  362.             validate_object_path(object_path)
  363.         
  364.         if isinstance(conn, BusName):
  365.             bus_name = conn
  366.             conn = bus_name.get_bus()
  367.         elif conn is None:
  368.             if bus_name is not None:
  369.                 conn = bus_name.get_bus()
  370.             
  371.         
  372.         self._object_path = None
  373.         self._connection = None
  374.         self._locations = []
  375.         self._locations_lock = thread.allocate_lock()
  376.         self._fallback = False
  377.         self._name = bus_name
  378.         if conn is None and object_path is not None:
  379.             raise TypeError('If object_path is given, either conn or bus_name is required')
  380.         object_path is not None
  381.         if conn is not None and object_path is not None:
  382.             self.add_to_connection(conn, object_path)
  383.         
  384.  
  385.     
  386.     def __dbus_object_path__(self):
  387.         '''The object-path at which this object is available.
  388.         Access raises AttributeError if there is no object path, or more than
  389.         one object path.
  390.  
  391.         Changed in 0.82.0: AttributeError can be raised.
  392.         '''
  393.         if self._object_path is _MANY:
  394.             raise AttributeError('Object %r has more than one object path: use Object.locations instead' % self)
  395.         self._object_path is _MANY
  396.         if self._object_path is None:
  397.             raise AttributeError('Object %r has no object path yet' % self)
  398.         self._object_path is None
  399.         return self._object_path
  400.  
  401.     __dbus_object_path__ = property(__dbus_object_path__)
  402.     
  403.     def connection(self):
  404.         '''The Connection on which this object is available.
  405.         Access raises AttributeError if there is no Connection, or more than
  406.         one Connection.
  407.  
  408.         Changed in 0.82.0: AttributeError can be raised.
  409.         '''
  410.         if self._connection is _MANY:
  411.             raise AttributeError('Object %r is on more than one Connection: use Object.locations instead' % self)
  412.         self._connection is _MANY
  413.         if self._connection is None:
  414.             raise AttributeError('Object %r has no Connection yet' % self)
  415.         self._connection is None
  416.         return self._connection
  417.  
  418.     connection = property(connection)
  419.     
  420.     def locations(self):
  421.         '''An iterable over tuples representing locations at which this
  422.         object is available.
  423.  
  424.         Each tuple has at least two items, but may have more in future
  425.         versions of dbus-python, so do not rely on their exact length.
  426.         The first two items are the dbus.connection.Connection and the object
  427.         path.
  428.  
  429.         :Since: 0.82.0
  430.         '''
  431.         return iter(self._locations)
  432.  
  433.     locations = property(locations)
  434.     
  435.     def add_to_connection(self, connection, path):
  436.         """Make this object accessible via the given D-Bus connection and
  437.         object path.
  438.  
  439.         :Parameters:
  440.             `connection` : dbus.connection.Connection
  441.                 Export the object on this connection. If the class attribute
  442.                 SUPPORTS_MULTIPLE_CONNECTIONS is False (default), this object
  443.                 can only be made available on one connection; if the class
  444.                 attribute is set True by a subclass, the object can be made
  445.                 available on more than one connection.
  446.  
  447.             `path` : dbus.ObjectPath or other str
  448.                 Place the object at this object path. If the class attribute
  449.                 SUPPORTS_MULTIPLE_OBJECT_PATHS is False (default), this object
  450.                 can only be made available at one object path; if the class
  451.                 attribute is set True by a subclass, the object can be made
  452.                 available with more than one object path.
  453.  
  454.         :Raises ValueError: if the object's class attributes do not allow the
  455.             object to be exported in the desired way.
  456.         :Since: 0.82.0
  457.         """
  458.         if path == LOCAL_PATH:
  459.             raise ValueError('Objects may not be exported on the reserved path %s' % LOCAL_PATH)
  460.         path == LOCAL_PATH
  461.         self._locations_lock.acquire()
  462.         
  463.         try:
  464.             if self._connection is not None and self._connection is not connection and not (self.SUPPORTS_MULTIPLE_CONNECTIONS):
  465.                 raise ValueError('%r is already exported on connection %r' % (self, self._connection))
  466.             not (self.SUPPORTS_MULTIPLE_CONNECTIONS)
  467.             if self._object_path is not None and not (self.SUPPORTS_MULTIPLE_OBJECT_PATHS) and self._object_path != path:
  468.                 raise ValueError('%r is already exported at object path %s' % (self, self._object_path))
  469.             self._object_path != path
  470.             connection._register_object_path(path, self._message_cb, self._unregister_cb, self._fallback)
  471.             if self._connection is None:
  472.                 self._connection = connection
  473.             elif self._connection is not connection:
  474.                 self._connection = _MANY
  475.             
  476.             if self._object_path is None:
  477.                 self._object_path = path
  478.             elif self._object_path != path:
  479.                 self._object_path = _MANY
  480.             
  481.             self._locations.append((connection, path, self._fallback))
  482.         finally:
  483.             self._locations_lock.release()
  484.  
  485.  
  486.     
  487.     def remove_from_connection(self, connection = None, path = None):
  488.         """Make this object inaccessible via the given D-Bus connection
  489.         and object path. If no connection or path is specified,
  490.         the object ceases to be accessible via any connection or path.
  491.  
  492.         :Parameters:
  493.             `connection` : dbus.connection.Connection or None
  494.                 Only remove the object from this Connection. If None,
  495.                 remove from all Connections on which it's exported.
  496.             `path` : dbus.ObjectPath or other str, or None
  497.                 Only remove the object from this object path. If None,
  498.                 remove from all object paths.
  499.         :Raises LookupError:
  500.             if the object was not exported on the requested connection
  501.             or path, or (if both are None) was not exported at all.
  502.         :Since: 0.81.1
  503.         """
  504.         self._locations_lock.acquire()
  505.         
  506.         try:
  507.             if self._object_path is None or self._connection is None:
  508.                 raise LookupError('%r is not exported' % self)
  509.             self._connection is None
  510.             if connection is not None or path is not None:
  511.                 dropped = []
  512.                 for location in self._locations:
  513.                     if connection is None or location[0] is connection:
  514.                         if path is None or location[1] == path:
  515.                             dropped.append(location)
  516.                             continue
  517.                 
  518.             else:
  519.                 dropped = self._locations
  520.                 self._locations = []
  521.             if not dropped:
  522.                 raise LookupError('%r is not exported at a location matching (%r,%r)' % (self, connection, path))
  523.             dropped
  524.             for location in dropped:
  525.                 
  526.                 try:
  527.                     location[0]._unregister_object_path(location[1])
  528.                 except LookupError:
  529.                     pass
  530.  
  531.                 if self._locations:
  532.                     
  533.                     try:
  534.                         self._locations.remove(location)
  535.                     except ValueError:
  536.                         pass
  537.                     except:
  538.                         None<EXCEPTION MATCH>ValueError
  539.                     
  540.  
  541.                 None<EXCEPTION MATCH>ValueError
  542.         finally:
  543.             self._locations_lock.release()
  544.  
  545.  
  546.     
  547.     def _unregister_cb(self, connection):
  548.         _logger.info('Unregistering exported object %r from some path on %r', self, connection)
  549.  
  550.     
  551.     def _message_cb(self, connection, message):
  552.         if not isinstance(message, MethodCallMessage):
  553.             return None
  554.         
  555.         try:
  556.             method_name = message.get_member()
  557.             interface_name = message.get_interface()
  558.             (candidate_method, parent_method) = _method_lookup(self, method_name, interface_name)
  559.             args = message.get_args_list(**parent_method._dbus_get_args_options)
  560.             keywords = { }
  561.             if parent_method._dbus_out_signature is not None:
  562.                 signature = Signature(parent_method._dbus_out_signature)
  563.             else:
  564.                 signature = None
  565.             if parent_method._dbus_async_callbacks:
  566.                 (return_callback, error_callback) = parent_method._dbus_async_callbacks
  567.                 
  568.                 keywords[return_callback] = lambda *retval: _method_reply_return(connection, message, method_name, signature, *retval)
  569.                 
  570.                 keywords[error_callback] = lambda exception: _method_reply_error(connection, message, exception)
  571.             
  572.             if parent_method._dbus_sender_keyword:
  573.                 keywords[parent_method._dbus_sender_keyword] = message.get_sender()
  574.             
  575.             if parent_method._dbus_path_keyword:
  576.                 keywords[parent_method._dbus_path_keyword] = message.get_path()
  577.             
  578.             if parent_method._dbus_rel_path_keyword:
  579.                 path = message.get_path()
  580.                 rel_path = path
  581.                 for exp in self._locations:
  582.                     if exp[0] is connection:
  583.                         if path == exp[1]:
  584.                             rel_path = '/'
  585.                             break
  586.                         
  587.                         if exp[1] == '/':
  588.                             continue
  589.                         
  590.                         if path.startswith(exp[1] + '/'):
  591.                             suffix = path[len(exp[1]):]
  592.                             if len(suffix) < len(rel_path):
  593.                                 rel_path = suffix
  594.                             
  595.                         
  596.                     path.startswith(exp[1] + '/')
  597.                 
  598.                 rel_path = ObjectPath(rel_path)
  599.                 keywords[parent_method._dbus_rel_path_keyword] = rel_path
  600.             
  601.             if parent_method._dbus_destination_keyword:
  602.                 keywords[parent_method._dbus_destination_keyword] = message.get_destination()
  603.             
  604.             if parent_method._dbus_message_keyword:
  605.                 keywords[parent_method._dbus_message_keyword] = message
  606.             
  607.             if parent_method._dbus_connection_keyword:
  608.                 keywords[parent_method._dbus_connection_keyword] = connection
  609.             
  610.             retval = candidate_method(self, *args, **keywords)
  611.             if parent_method._dbus_async_callbacks:
  612.                 return None
  613.             if signature is not None:
  614.                 signature_tuple = tuple(signature)
  615.                 if len(signature_tuple) == 0:
  616.                     if retval == None:
  617.                         retval = ()
  618.                     else:
  619.                         raise TypeError('%s has an empty output signature but did not return None' % method_name)
  620.                 retval == None
  621.                 if len(signature_tuple) == 1:
  622.                     retval = (retval,)
  623.                 elif operator.isSequenceType(retval):
  624.                     pass
  625.                 else:
  626.                     raise TypeError('%s has multiple output values in signature %s but did not return a sequence' % (method_name, signature))
  627.             len(signature_tuple) == 1
  628.             if retval is None:
  629.                 retval = ()
  630.             elif isinstance(retval, tuple) and not isinstance(retval, Struct):
  631.                 pass
  632.             else:
  633.                 retval = (retval,)
  634.             _method_reply_return(connection, message, method_name, signature, *retval)
  635.         except Exception:
  636.             isinstance(message, MethodCallMessage)
  637.             exception = isinstance(message, MethodCallMessage)
  638.             _method_reply_error(connection, message, exception)
  639.         except:
  640.             isinstance(message, MethodCallMessage)
  641.  
  642.  
  643.     
  644.     def Introspect(self, object_path, connection):
  645.         """Return a string of XML encoding this object's supported interfaces,
  646.         methods and signals.
  647.         """
  648.         reflection_data = _dbus_bindings.DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE
  649.         reflection_data += '<node name="%s">\n' % object_path
  650.         interfaces = self._dbus_class_table[self.__class__.__module__ + '.' + self.__class__.__name__]
  651.         for name, funcs in interfaces.iteritems():
  652.             reflection_data += '  <interface name="%s">\n' % name
  653.             for func in funcs.values():
  654.                 if getattr(func, '_dbus_is_method', False):
  655.                     reflection_data += self.__class__._reflect_on_method(func)
  656.                     continue
  657.                 if getattr(func, '_dbus_is_signal', False):
  658.                     reflection_data += self.__class__._reflect_on_signal(func)
  659.                     continue
  660.             
  661.             reflection_data += '  </interface>\n'
  662.         
  663.         for name in connection.list_exported_child_objects(object_path):
  664.             reflection_data += '  <node name="%s"/>\n' % name
  665.         
  666.         reflection_data += '</node>\n'
  667.         return reflection_data
  668.  
  669.     Introspect = method(INTROSPECTABLE_IFACE, in_signature = '', out_signature = 's', path_keyword = 'object_path', connection_keyword = 'connection')(Introspect)
  670.     
  671.     def __repr__(self):
  672.         where = ''
  673.         if self._object_path is not _MANY and self._object_path is not None:
  674.             where = ' at %s' % self._object_path
  675.         
  676.         return '<%s.%s%s at %#x>' % (self.__class__.__module__, self.__class__.__name__, where, id(self))
  677.  
  678.     __str__ = __repr__
  679.  
  680.  
  681. class FallbackObject(Object):
  682.     '''An object that implements an entire subtree of the object-path
  683.     tree.
  684.  
  685.     :Since: 0.82.0
  686.     '''
  687.     SUPPORTS_MULTIPLE_OBJECT_PATHS = True
  688.     
  689.     def __init__(self, conn = None, object_path = None):
  690.         """Constructor.
  691.  
  692.         Note that the superclass' ``bus_name`` __init__ argument is not
  693.         supported here.
  694.  
  695.         :Parameters:
  696.             `conn` : dbus.connection.Connection or None
  697.                 The connection on which to export this object. If this is not
  698.                 None, an `object_path` must also be provided.
  699.  
  700.                 If None, the object is not initially available on any
  701.                 Connection.
  702.  
  703.             `object_path` : str or None
  704.                 A D-Bus object path at which to make this Object available
  705.                 immediately. If this is not None, a `conn` must also be
  706.                 provided.
  707.  
  708.                 This object will implements all object-paths in the subtree
  709.                 starting at this object-path, except where a more specific
  710.                 object has been added.
  711.         """
  712.         super(FallbackObject, self).__init__()
  713.         self._fallback = True
  714.         if conn is None:
  715.             if object_path is not None:
  716.                 raise TypeError('If object_path is given, conn is required')
  717.             object_path is not None
  718.         elif object_path is None:
  719.             raise TypeError('If conn is given, object_path is required')
  720.         else:
  721.             self.add_to_connection(conn, object_path)
  722.  
  723.  
  724.